package org.trackcore.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.trackcore.common.BaseResponse;
import org.trackcore.common.ErrorCode;
import org.trackcore.common.ResultUtils;
import org.trackcore.dispatcher.MonitorDataDispatcher;
import org.trackcore.model.vo.MonitorDataVO;
import org.trackcore.service.MonitorDataService;

import java.util.Map;

@RestController
@RequestMapping("/monitor")
@Api(tags = "监控数据接口")
public class MonitorDataController {
    @Autowired
    private MonitorDataDispatcher dispatcher;
//    @PostMapping("/collect")
//    @ApiOperation("收集监控数据")
//    public BaseResponse collectData(@RequestBody Map<String, Object> rawData) {
//        // 基本校验
//        if (rawData == null || !rawData.containsKey("type")) {
//            return ResultUtils.error(ErrorCode.PARAMS_ERROR, "数据格式错误");
//        }
//
//        // 统一处理入口
//        monitorDataService.processMonitorData(rawData);
//        return ResultUtils.success();
//    }


    @PostMapping("/collect")
    @ApiOperation("收集监控数据")
    public BaseResponse collect(@RequestBody Map<String, Object> rawData) {
        try {
            dispatcher.dispatch(rawData);
            return ResultUtils.success();
        } catch (IllegalArgumentException e) {
            return ResultUtils.error(400, e.getMessage());
        }
    }

}
